package com.ziyun.erp.modules.store.storeGoodsProduct.service.impl;

import com.utility.StringUtils;
import com.ziyun.erp.modules.store.storeGoodsProduct.dao.StoreGoodsProductDao;
import com.ziyun.erp.modules.store.storeGoodsProduct.entity.StoreGoodsProductEntity;
import com.ziyun.erp.modules.store.storeGoodsProduct.service.StoreGoodsProductService;
import io.renren.common.utils.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;



@Service("storeGoodsProductService")
public class StoreGoodsProductServiceImpl extends ServiceImpl<StoreGoodsProductDao, StoreGoodsProductEntity> implements StoreGoodsProductService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Integer productId = StringUtil.getRequestParamInteger(params.get("productId"));
        Integer origProductId = StringUtil.getRequestParamInteger(params.get("origProductId"));
        String productName = StringUtil.getRequestParamString(params.get("productName"));
        Page<StoreGoodsProductEntity> page = this.selectPage(
                new Query<StoreGoodsProductEntity>(params).getPage(),
                new EntityWrapper<StoreGoodsProductEntity>()
                .eq("disabled",0)
                .eq(origProductId != null,"orig_product_id",origProductId)
                .eq(productId != null,"product_id",productId)
                .like(productName!=null,"product_name",productName)
        );

        return new PageUtils(page);
    }

    @Override
    public void flagDelete(Integer[] productIds) {
        this.baseMapper.flagDelete(StringUtils.join(productIds,","));
    }

}
